package me.zhengjie.controller.PPMoveController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.ppService.PPMoveService;
import me.zhengjie.pojo.PPMoveMissionParameter;
import me.zhengjie.pojo.Resp;
import me.zhengjie.pojo.sqlServer.PPStorage;
import me.zhengjie.service.PPStorageService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: xinglin
 * @CreateTime: 2024-08-21
 * @Description: PP移库控制层接口
 * @Version: 1.0
 */

@RestController
@RequiredArgsConstructor
@Api(tags = "pp移库管理")
@RequestMapping("/api/ppMove")
public class PPMoveController {

    private final PPMoveService ppMoveService;
    private final PPStorageService ppStorageService;



    @PostMapping("/createMoveMisson" )
    @Log("创建pp移库任务")
    @ApiOperation("创建pp移库任务")
//    @PreAuthorize("@el.check('ppMove:add')")
    public Resp createMoveMisson(@RequestBody PPMoveMissionParameter ppMoveMissionParameter){
        try {
            ppMoveService.createPPMoveMission(ppMoveMissionParameter);
            return Resp.builder()
                    .msg("生成移库任务成功")
                    .status(200)
                    .build();
        }catch (Exception e){
            return Resp.builder()
                    .msg("生成移库任务失败")
                    .status(500)
                    .build();

        }

    }


    @GetMapping("/getStroageCodes" )
    @Log("获取储位码")
    @ApiOperation("获取储位码")
//    @PreAuthorize("@el.check('ppMove:get')")
    public Resp getStroageCodes(){
      try {
          List<PPStorage> ppStorages = ppStorageService.findSuitableStorage();

          List<String> ppStorageCodes = ppStorages.stream().map(PPStorage::getStorageCode).collect(Collectors.toList());

          return Resp.builder()
                  .data("ppStorageCodes", ppStorageCodes)
                  .msg("获取储位码成功")
                  .status(200)
                  .build();
      }
      catch (Exception e){
          return Resp.builder()
                  .msg("获取储位码失败")
                  .status(500)
                  .build();
      }


    }






}


